<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="purchasingListForm" :model="purchasingListFormData" :rules="rules" size="mini"
        label-width="100px">
        <el-col :span="12">
          <el-form-item label="选择合同" prop="contractId">
            <el-select v-model="purchasingListFormData.contractId" placeholder="请选择选择合同" filterable
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in contractIdOptions" :key="index" :label="item.contractName"
                :value="item.contractId" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否已付款" prop="paid">
            <el-select :disabled="true" v-model="purchasingListFormData.paid" placeholder="请选择是否已付款" :style="{width: '100%'}">
              <el-option v-for="(item, index) in paidOptions" :key="index" :label="item.label"
                :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="清单名" prop="purchasingListName">
            <el-input v-model="purchasingListFormData.purchasingListName" placeholder="请输入清单名" :maxlength="20"
              show-word-limit clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="总金额" prop="purchasingListTotalCost">
            <el-input v-model="purchasingListFormData.purchasingListTotalCost" placeholder="请输入总金额" readonly
              :disabled='true' :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">创建</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import {purchasingListCreate} from '@/api/sale'
export default {
  components: {},
  props: ['contractList'],
  data() {
    return {
      purchasingListFormData: {
        contractId: undefined,
        paid: 0,
        purchasingListName: "",
        purchasingListTotalCost: 0,
      },
      rules: {
        contractId: [{
          required: true,
          message: '请选择选择合同',
          trigger: 'change'
        }],
        paid: [{
          required: true,
          message: '请选择是否已付款',
          trigger: 'change'
        }],
        purchasingListName: [{
          required: true,
          message: '请输入清单名',
          trigger: 'blur'
        }],
        purchasingListTotalCost: [{
          required: true,
          message: '请输入总金额',
          trigger: 'blur'
        }],
      },
      contractIdOptions: [],
      paidOptions: [{
        "label": "未付款",
        "value": 0
      }, {
        "label": "已付款",
        "value": 1
      }],
    }
  },
  computed: {},
  watch: {
    contractList: function(n, o){
      this.contractIdOptions = n
    }
  },
  created() {
    this.contractIdOptions = this.contractList
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['purchasingListForm'].validate(valid => {
        if (!valid) return
        purchasingListCreate(this.purchasingListFormData)
      })
    },
    resetForm() {
      this.$refs['purchasingListForm'].resetFields()
    },
    
  }
}

</script>
<style>
</style>
